// 数字自增动画
/**
 * 数字增加动画效果
 * How to use ?
 * <div v-countRun="200" step="5">0</div>
 */
export default {
  mounted(el: HTMLElement, binding: any) {
    let timer: any = null;
    const step = Number(el.getAttribute("step"))
      ? Number(el.getAttribute("step"))
      : 10;
    const targetDomCount = Number(binding.value); // 目标数字
    let nowCount = 0; //当前页面显示值
    timer = setInterval(() => {
      if (nowCount < targetDomCount) {
        nowCount += step;
      } else {
        nowCount = targetDomCount;
        clearInterval(timer);
      }
      el.innerHTML = nowCount.toString();
    }, 0);
  },
};
